﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WordNet.Core.ElementContracts;
using WordNet.Core.Relations;

namespace WordNet.Core
{
    public class SenseNode:ISenseNode
    {
        ISynset _synset;
        String _words;
        ISenseNode[] _children;
        int N;
        public SenseNode(ISynset synset, int size)
        {
            _synset = synset;
            _children = new ISenseNode[size];
            _words = GetWords();
        }
        public ISynset Synset
        {
            get { return _synset; }
        }

        public string Words
        {
            get { return _words; }
        }

        public int Size
        {
            get { return _children.Length; }
        }

        public ISenseNode this[int i]
        {
            get
            {
                return _children[i];
            }
            set
            {
                _children[i] = value;
                N++;
            }
        }

        public ISenseNode[] Next
        {
            get { return _children; }
        }

        private string GetWords()
        {
            string s = string.Empty;
            foreach (var w in _synset.GetWords())
            {
                if (s != string.Empty)
                    s += "; ";
                s = s + w.Lemma;
            }
            return s.Trim();
        }


        public void Add(ISenseNode node)
        {
            _children[N++] = node;
        }
    }
}
